const express = require('express');

const app = express();

// 定义一个最简单的中间件函数
const mw = function(req, res, next) {
  console.log('最简单的中间件函数');
  // 中间件共享req res中的属性
  req.startTime = new Date();
  next();
}

app.use(mw);

app.get('/', (req, res) => {
  console.log('调用了/', req.startTime);
  res.send('Hello World!');
});

app.get('/user', (req, res) => {
  console.log('调用了user', req.startTime);
  res.send('user Hello World!');
});

app.listen(3000, () => {
  console.log('Server listening on port 3000');
} );